package com.xjrsoft.common.handler;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;
import org.springframework.stereotype.Component;

import java.sql.*;

@Component
@MappedTypes(Clob.class)
public class ClobTypeHandler extends BaseTypeHandler<Clob> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Clob parameter, JdbcType jdbcType) throws SQLException {
        ps.setCharacterStream(i, parameter.getCharacterStream());
    }

    @Override
    public Clob getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return rs.getClob(columnName);
    }

    @Override
    public Clob getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return rs.getClob(columnIndex);
    }

    @Override
    public Clob getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return cs.getClob(columnIndex);
    }
}
